using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Bymed.SpineScan.DataModel;

namespace Bymed.SpineScan.Repository.EntityFramework.Mapping
{
    public class TestTrackingMap : EntityTypeConfiguration<TestTracking>
    {
        public TestTrackingMap()
        {
            // Primary Key
            this.HasKey(t => t.TestTimestamp);

            // Properties
            this.Property(t => t.TestTimestamp)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.PatientNumber)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.AttendingDoctorName)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.AttachedDiagnosticMessage)
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("TestTracking");
            this.Property(t => t.TestTimestamp).HasColumnName("TestTimestamp");
            this.Property(t => t.PatientNumber).HasColumnName("PatientNumber");
            this.Property(t => t.AttendingDoctorName).HasColumnName("AttendingDoctorName");
            this.Property(t => t.AttachedDiagnosticMessage).HasColumnName("AttachedDiagnosticMessage");
            this.Property(t => t.TestDate).HasColumnName("TestDate");

            // Relationships
            this.HasRequired(t => t.Patient)
                .WithMany(t => t.TestTrackings)
                .HasForeignKey(d => d.PatientNumber);
        }
    }
}
